Imports System.Web.SessionState
Imports System
Imports System.Web.Routing
Imports System.Web
Imports System.Web.Compilation
Imports System.Collections


Public Class PageRouteHandler
    Implements IRouteHandler

    Private _virtualPath As String

    Public Sub New(ByVal vPath As String)
        _virtualPath = vPath
    End Sub

    Public Property VirtualPath() As String
        Get
            Return _virtualPath
        End Get
        Private Set(ByVal value As String)
            _virtualPath = value
        End Set
    End Property

    Public Function GetHttpHandler(ByVal requestContext _
          As System.Web.Routing.RequestContext) _
          As System.Web.IHttpHandler _
          Implements System.Web.Routing.IRouteHandler.GetHttpHandler

        Dim redirectPage As IHttpHandler

        redirectPage = CType(BuildManager.CreateInstanceFromVirtualPath _
            (VirtualPath, GetType(System.Web.UI.Page)), IHttpHandler)


        For Each urlParm In requestContext.RouteData.Values
            requestContext.HttpContext.Items(urlParm.Key) = urlParm.Value
        Next

        Return redirectPage

    End Function
End Class
